def findTargetSumWays(nums, target: int) -> int:
    total = sum(nums)
    if abs(target) > abs(total):
        return 0
    max_len = total * 2 + 1
    dp = [[0] * max_len for i in range(0, len(nums))]

    def real_num(j):
        return j - total

    for j in range(0, max_len):
        if nums[0] == real_num(j):
            dp[0][j] += 1
        if nums[0] * -1 == real_num(j):
            dp[0][j] += 1
    for i in range(1, len(nums)):
        for j in range(0, max_len):
            l = j - nums[i] if j - nums[i] >= 0 else 0
            r = j + nums[i] if j + nums[i] < max_len else 0
            dp[i][j] += dp[i - 1][l]
            dp[i][j] += dp[i - 1][r]
    return dp[-1][target + total]


print(findTargetSumWays([0, 0, 1], 2))
